﻿@{
    ViewData["Title"] = "注册";
}      
<h5>@ViewData["Title"]</h5>
<table class="table">
    <tr>
        <td>用户名</td>
        <td><input id="TBUserName" type="text" class="form-control" maxlength="10" /></td>
        <td><small id="SUserName" class="text-warning"></small></td>
    </tr>
    <tr>
        <td>密码</td>
        <td><input id="TBPassword" type="password" class="form-control" maxlength="16" /></td>
        <td><small id="SPassword" class="text-warning"></small></td>
    </tr>
    <tr>
        <td>重输密码</td>
        <td><input id="TBPassword2" type="password" class="form-control" maxlength="16" /></td>
        <td><small id="SPassword2" class="text-warning"></small></td>
    </tr>
    <tr><td colspan="3"><button class="btn btn-primary" onclick="Save()">注册</button></td></tr>
</table>

@section Scripts
{
    <script>

        $(function () {

            $("#TBUserName").change(function () {
                if ($("#TBUserName").val() == "") {
                    $("#SUserName").html("用户名不能为空");
                }
                CallAjax("@Url.Action("CheckUserName")", {
                    userName: $("#TBUserName").val()
                }, function (ret) {
                        if (ret.message == 1)
                            $("#SUserName").html("用户名已经存在");
                        else
                            $("#SUserName").html("");
                });
            });


            $("#TBPassword").change(function () {
                if ($("#TBPassword").val().length<6) {
                    $("#SPassword").html("密码长度不能小于6");
                }
                else
                    $("#SPassword").html("");
            });

            $("#TBPassword2").change(function () {
                if ($("#TBPassword").val()!=$("#TBPassword2").val()) {
                    $("#SPassword2").html("两次输入密码不一样");
                }
                else
                    $("#SPassword2").html("");
            });

        });


        function Save() {

            if ($("#TBUserName").val() == "") {
                ShowMessage("用户名不能为空");
                return;
            }
            if ($("#TBPassword").val().length < 6) {
                ShowMessage("密码长度不能小于6");
                return;
            }
            if ($("#TBPassword").val() != $("#TBPassword2").val()) {
                ShowMessage("两次输入密码不一样");
                return;
            }

            CallAjax("@Url.Action("Save")", {
                userName: $("#TBUserName").val(),
                password:$("#TBPassword").val()
            }, function (ret) {
                    ShowMessage(ret.message);
            });

        }
    </script>

}